//: [Previous](@previous)

import Foundation
import UIKit
var str = "Hello, playground"

//: [Next](@next)
/*
 OC定义字符串: NSString *str = @"hello world";
 
 Swift定义字符串: let str = "我要飞的更高"
 
 String的特点:
 1.String是结构体,效率比NSString略高
 2.String支持直接遍历里面的字符
 3.String提供了和NSString一样的绝大部分功能
 4.String和NSString之间转换方便: addr2 as NSString
 */

// String
// 不用@符号


let str1 = "jhdfg"


// 遍历字符串

for c in str1.characters
{
    print(c)
}

// 字符串长度
let length = str1.characters.count
// 字符串拼接
// OC [NSString stringWithFormat:]
// 字符串和字符串拼接
let h = "hello"
let w = "world"

let hw = h + " " + w

// 非字符换和字符串拼接

let n = 32
let z = "个赞"

let nz = String(n) + z

let size = CGSize(width: 100 ,height: 100)


// "\()" 可以变量或常量转成字符串
let nz1 = "\(n)" + z

let nz2 = "\(n)" + "\(z)"

// 字符串格式化
let pi = 3.14984874

//可变参数,参数个数可以任意,类型也任意

let p = String(format: "%.02f",pi)

// 常用操作, 判断一个地址是不是git图片地址

let addr = "www.baidu.com/aa/bb/cc.Gif"

// 转成小写

let addr1 = addr.lowercaseString


// 判断是否是以gif结尾

addr1.hasSuffix("gif")


// 字符串截串,建议转成NSString来截串
let addr2 = addr1 as NSString

let last = addr2.substringFromIndex(addr2.length - 3)

// 字符串判断相同直接使用 ==
last == "gif"




